<template>
	<Layout class="p-5 bg-white">
		<Form :label-width="80">
			<FormItem class="w-50" label="门店名称">
				<Input v-model="store.name" placeholder="请输入门店名称"></Input>
			</FormItem>
			<FormItem class="w-50" label="门店地址">
				<Input v-model="store.address" placeholder="请输入门店地址"></Input>
			</FormItem>
			<FormItem class="w-50" label="联系电话">
				<Input v-model="store.conTel" placeholder="请输入联系电话"></Input>
			</FormItem>
			<FormItem class="w-50" label="联系人">
				<Input v-model="store.conPerson" placeholder="请输入联系人"></Input>
			</FormItem>
			<FormItem class="w-50" label="门店描述">
				<Input type="textarea" v-model="store.des" placeholder="请输入门店描述"></Input>
			</FormItem>
			<FormItem class="w-50" label="账号">
				<Input v-model="store.account" placeholder="请输入账号"></Input>
			</FormItem>
			<FormItem class="w-50" label="密码">
				<Input v-model="store.password" placeholder="请输入密码"></Input>
			</FormItem>
			<FormItem class="w-50" label="确认密码">
				<Input v-model="store.repeatPassword" placeholder="请再次输入密码"></Input>
			</FormItem>
			<FormItem class="text-right"> 
				<Button @click="submit" type="primary">提交</Button>
				<Button @click="cancel" class="ml-2">取消</Button>
			</FormItem>
		</Form>
	</Layout>
</template>

<script>
	export default {
		data() {
			return {
				allPermissions: [],
				store: {
					name: "",
					address: "",
					conTel: "",
					conPerson: "",
					des: "",
					account:"",
					password:"",
					repeatPassword:"",
				}
			}
		},
		methods: {
			submit: function() {
				
				if (this.store.name.length === 0) {
					this.message.error("门店名称必须输入");
					return;
				}
				
				if (this.store.address.length === 0) {
					this.message.error("门店地址必须输入");
					return;
				}
				
				const reg =/^[1][3-9][0-9]{9}$/;
				if (!this.util.isRealNum(this.store.conTel)) {
					this.message.error("联系电话必须输入");
					return;
				}
				if((!reg.test(this.store.conTel))){
					this.message.error("电话号码不符合规范");
					return;
				}
				
				if (this.store.conPerson.length === 0) {
					this.message.error("联系人必须输入");
					return;
				}
				
				if(this.store.account.length === 0){
					this.message.error("账号必须输入");
					return;
				}
				
				if(this.store.password.length === 0){
					this.message.error("密码必须输入");
					return;
				}
				
				if(this.store.password !== this.store.repeatPassword){
					this.message.error("两次输入的密码不同");
					return;
				}
				
				let self = this;
	
				this.http.post({
					url: "/store/store/info",
					param:{
						param:this.store
					}
				}).then(data => {
					self.message.info("新增成功");
					this.$tabs.close();
				});
			},
			cancel: function() {
				this.$tabs.close();
			}
		}
	}
</script>

<style>
</style>
